package com.shycloud.mido.member.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.member.api.entity.ErpActivityInfo;
import com.shycloud.mido.member.mapper.ErpActivityInfoMapper;
import com.shycloud.mido.member.service.ActivityService;

import lombok.AllArgsConstructor;

/**
 * @author Xiaoxing Yu
 * @date 2020/6/2
 **/
@Service
@AllArgsConstructor
public class ActivityServiceImpl extends ServiceImpl<ErpActivityInfoMapper, ErpActivityInfo> implements ActivityService {

	private ErpActivityInfoMapper erpActivityInfoMapper;

	@Override
	public R addActivity(ErpActivityInfo entity) {

		//创建时间
		entity.setCreateTime(LocalDateTime.now());
		//更新操作
		boolean updateResult = erpActivityInfoMapper.insert(entity) == 1 ? true : false;

		return new R<>(updateResult);
	}

	@Override
	public R getAllActivity() {
		List<ErpActivityInfo> actList = erpActivityInfoMapper.selectList(new QueryWrapper<ErpActivityInfo>());
		return new R(actList);
	}

	@Override
	public R delAllActivity(Integer id) {
		int result = erpActivityInfoMapper.deleteById(id);
		return new R(result == 0 ? false : true);
	}

}
